//
//  LocalesViewController.m
//  Futbol5Final
//
//  Created by Johan Chaves on 4/14/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "LocalesViewController.h"
#import "LocalCreator.h"
#import "LocalVO.h"

@implementation LocalesViewController

@synthesize locales,canchasViewController;

- (id) initWithLocales :(DistritosVO*)pdistrito:(NSDictionary *) localesData{
    [locales dealloc];
    [locales release];
    
    self = [[[LocalesViewController alloc] initWithNibName:@"LocalesViewController" bundle:nil] autorelease];
    
    LocalCreator *localesCreator = [[LocalCreator alloc]init];
    
    locales = [localesCreator createLocales:pdistrito:localesData];
    
    return self;
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [locales count];
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"distrito";
    
    DistritosVO *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [locales objectAtIndex:indexPath.row];
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
    }
    
    return cell;
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    LocalVO *locals = (LocalVO*)[tableView cellForRowAtIndexPath:indexPath];        
    
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
	    
        self.canchasViewController = [[CanchasViewController alloc]initWithCanchas:locals:[locals canchas]];
        
	    
        
        [self.navigationController pushViewController:self.canchasViewController animated:YES];
    }  
    
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = @"Locales";
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end